package co.edu.usbcali.ai.ga.factories;

import co.edu.usbcali.ai.ga.ICromosom;
import co.edu.usbcali.ai.ga.CromosomType;
import co.edu.usbcali.ai.ga.Gene;
import co.edu.usbcali.ai.ga.GeneType;
import co.edu.usbcali.ai.ga.Breed;

public class CromosomFactory {
	
	public static ICromosom createAleatoryCromosom(Breed p_race) throws InstantiationException, IllegalAccessException{
		ICromosom cromosom=p_race.getCromosomClass().newInstance();
		CromosomType cromosomType=p_race.getCromosomType();
		cromosom.setType(cromosomType);
		if (cromosomType.getSizeType()==CromosomType.FIXED_SIZE){
			if (cromosomType.getType()==CromosomType.HETEREOGENE){
				for (int con=0;con<cromosomType.getSize();con++){
					Gene gene=GeneFactory.createAleatoryGene(cromosomType.getGeneTypes().get(con));
					cromosom.add(gene);
				}
			}else{
				GeneType geneType=cromosomType.getGeneTypes().get(0);
				for (int con=0;con<cromosomType.getSize();con++){
					Gene gene=GeneFactory.createAleatoryGene(geneType);
					cromosom.add(gene);
				}
			}
		}
		return cromosom;
	}

}
